package com.woniu.gym.controller;



import com.woniu.core.util.*;
import com.woniu.gym.dto.CoachJobApplicationDto;
import com.woniu.gym.dto.GymApplicationCoachDto;
import com.woniu.gym.form.SearchCoachApplicationForm;
import com.woniu.gym.form.SearchGymApplicationForm;
import com.woniu.gym.model.TApply;
import com.woniu.gym.service.TApplyService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


import io.swagger.models.auth.In;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2024年04月02日
 */
@RestController
@RequestMapping("/tApply")
@Api(tags = "招聘申请表相关业务")
public class TApplyController {
    @Resource
    private TApplyService tApplyService;

    @Resource
    private RedisUtil redisUtil;
    @ApiOperation("教练查询已投简历的招聘信息")
    @GetMapping("/findApplication.coach")
    public Result findApplication(SearchCoachApplicationForm form, @RequestHeader String token) throws Exception {
        String refreshToken = redisUtil.get(token);
        int coachId = Integer.parseInt(JwtUtil.parseToken(refreshToken,3).get("coachId").toString());
        form.setCoachId(coachId);
        PageInfo<CoachJobApplicationDto> dto = tApplyService.findApplication(form);
        return  Result.getResult(PageInfo.class).setMsg("查询成功").setData(dto);
    }

    @ApiOperation("场馆查询求职申请信息")
    @GetMapping("/gymApplication.gym")
    public Result gymApplication(SearchGymApplicationForm form) throws Exception {
        PageInfo<GymApplicationCoachDto> dto = tApplyService.gymApplication(form);
        return  Result.getResult(PageInfo.class).setMsg("查询成功").setData(dto);
    }

    @ApiOperation("教练求职申请 教练->场馆")
    @GetMapping("/coachJobApplication/.coach")
    public Result<CoachJobApplicationDto> coachJobApplication( Integer recruitId,@RequestHeader String token) throws Exception {
        String refreshToken = redisUtil.get(token);
        int coachId = Integer.parseInt(JwtUtil.parseToken(refreshToken,3).get("coachId").toString());
        CoachJobApplicationDto dto = tApplyService.coachJobApplication(recruitId,coachId);
        return Result.getResult(CoachJobApplicationDto.class).setMsg("投递求职申请成功").setData(dto);
    }
    @ApiOperation("场馆招聘申请 场馆->教练")
    @GetMapping("/gymRecruitApplication.gym")
    public Result<GymApplicationCoachDto> gymRecruitApplication(Integer recruitId,Integer coachId){
        GymApplicationCoachDto dto = tApplyService.gymRecruitApplication(recruitId,coachId);
        return  Result.getResult(GymApplicationCoachDto.class).setMsg("投递招聘信息成功").setData(dto);
    }
    @ApiOperation("教练取消求职申请")
    @GetMapping("/coachCancelApplication.coach")
    public Result<TApply> coachCancelApplication(Integer applyId, @RequestHeader String token) throws Exception {
        String refreshToken = redisUtil.get(token);
        int coachId = Integer.parseInt(JwtUtil.parseToken(refreshToken,3).get("coachId").toString());
        TApply tApply = tApplyService.cancelApplication(applyId,coachId);
        return Result.getResult(TApply.class).setMsg("取消成功").setData(tApply);
    }

    @ApiOperation("场馆取消招聘申请")
    @GetMapping("/gymCancelApplication.gym")
    public Result<TApply> gymCancelApplication(Integer applyId){
        TApply tApply = tApplyService.gymCancelApplication(applyId);
        return Result.getResult(TApply.class).setMsg("取消成功").setData(tApply);
    }
    @ApiOperation("教练审核招聘信息或场馆审核求职信息（通过则自动签约）")
    @GetMapping("/auditInformation")
    public Result<TApply> auditInformation( Integer applyId,Integer state){
        TApply tApply = tApplyService.auditInformation(applyId,state);
        return Result.getResult(TApply.class).setMsg("审核完成").setData(tApply);
    }

}

